Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add empty_drop #8571

Merged
merged 1 commit into from
Apr 21, 2022
Merged

add empty_drop #8571

merged 1 commit into from
Apr 21, 2022

Conversation

PyroTechniac
Copy link
Contributor

Closes #8352

changelog: New lint [empty_drop]

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @flip1995 (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 21, 2022
@PyroTechniac
Copy link
Contributor Author

After some discussion with fellow devs, they advise I switch this from correctness to style, but would like input from the devs

@flip1995
Copy link
Member

As you can see on many Clippy tests, lints behave differently on types that have a Drop implementation. The same is true for rustc. So even though this Drop might not do anything, it might still be used as a marker. (I'm not sure if this has real world use cases, but removing the Drop impl changes compiler behavior.)

One example where you might want to use this is rustc --explain E0509. You can implement an empty Drop impl to prevent any code from moving fields out of a struct.

Since there isn't any alternative to implementing Drop to tell the compiler that a type has drop glue / a destructor, I'm not sure if this lint should be warn-by-default. If you implement an empty Drop you probably have a good reason to do so. And if the empty Drop impl is by accident it doesn't do harm during runtime.

So for me the question is if this lint should be pedantic or restriction. I tend towards restriction.

@PyroTechniac
Copy link
Contributor Author

I have changed the lint to be a restriction lint

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks I only noticed an edge case that you might want to address and some comments about the documentation. Great first contribution overall!

clippy_lints/src/empty_drop.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_drop.rs Outdated Show resolved Hide resolved
clippy_lints/src/empty_drop.rs Show resolved Hide resolved
clippy_lints/src/empty_drop.rs Outdated Show resolved Hide resolved
tests/ui/crashes/ice-7410.rs Outdated Show resolved Hide resolved
tests/ui/empty_drop.rs Show resolved Hide resolved
Comment on lines 51 to 52
// span_lint_and_help(cx, EMPTY_DROP, item.span, "empty drop implementation", None, "try removing this impl");
span_lint_and_sugg(cx, EMPTY_DROP, item.span, "empty drop implementation", "try removing this impl", String::new(), Applicability::MaybeIncorrect);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// span_lint_and_help(cx, EMPTY_DROP, item.span, "empty drop implementation", None, "try removing this impl");
span_lint_and_sugg(cx, EMPTY_DROP, item.span, "empty drop implementation", "try removing this impl", String::new(), Applicability::MaybeIncorrect);
span_lint_and_sugg(
cx,
EMPTY_DROP,
item.span,
"empty drop implementation",
"try removing this impl",
String::new(),
Applicability::MaybeIncorrect,
);

clippy_lints/src/empty_drop.rs Outdated Show resolved Hide resolved
tests/ui/empty_drop.stderr Outdated Show resolved Hide resolved
@PyroTechniac
Copy link
Contributor Author

Do I still need the main fn in my tests?

@flip1995
Copy link
Member

Do I still need the main fn in my tests?

Not sure if you can completely remove it (I don't think so), but you can leave it empty.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. With squashed commits and CI passing, this should be ready to get merged.

@PyroTechniac
Copy link
Contributor Author

I'm not quite a git master, is there anything I have to do for squashing commits?

@flip1995
Copy link
Member

Let me do it for you then. You can do this with git rebase -i master and then force pushing the new commit. Before force pushing you should make sure that your diff with the remote (origin/empty-drop in this case is empty though)

@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Mar 30, 2022

☔ The latest upstream changes (presumably #8576) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

This will need another rebase.

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 31, 2022
@PyroTechniac
Copy link
Contributor Author

Sorry! Got caught up this weekend, I'll get to this sometime tonight however.

@PyroTechniac
Copy link
Contributor Author

And by tonight I meant 2 days later, sorry for the delay!

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM now. Great first contribution.

Can you squash your commits please. While you're at it you can also rebase them on the current master to get rid of merge commits. The Rust porject has a no-merge-policy

You can do this with:

git rebase -i master
# An editor will open, where you can "squash" your commits
# You might have to fix some conflicts
git diff -- clippy_lints/src/empty_drop.rs  # Should be empty

I recommend that you run the usual commands again:

cargo dev update_lints
cargo dev fmt
cargo test

If all that passes, you can force push your changes

git push --force-with-lease

@flip1995
Copy link
Member

This rebased seemed to have gone wrong. Let me try to fix that.

@flip1995
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 21, 2022

📌 Commit 7a99a1c has been approved by flip1995

bors added a commit that referenced this pull request Apr 21, 2022
add `empty_drop`

Closes #8352

changelog: New lint [`empty_drop`]
@bors
Copy link
Contributor

bors commented Apr 21, 2022

⌛ Testing commit 7a99a1c with merge 8848535...

@bors
Copy link
Contributor

bors commented Apr 21, 2022

💔 Test failed - checks-action_dev_test

@flip1995
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 21, 2022

📌 Commit 8de3fb1 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Apr 21, 2022

⌛ Testing commit 8de3fb1 with merge a9d31e7...

@bors
Copy link
Contributor

bors commented Apr 21, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing a9d31e7 to master...

@bors bors merged commit a9d31e7 into rust-lang:master Apr 21, 2022
@PyroTechniac
Copy link
Contributor Author

Thank you! Someone had made a fixed branch for me but I didn't get the chance to fix it yesterday

@PyroTechniac PyroTechniac deleted the empty-drop branch April 21, 2022 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint: empty drop
4 participants